<script>
$(function(){
	$.post('{{ urlfor "ProductsController.GetOptions"}}', {'fields':['goods_function_info','goods_mouting_genre']}, function(res){
		var goods_mouting_genre = res.data.goods_mouting_genre;
		var goods_function_info = res.data.goods_function_info;
		$('#genre').html(setOptions(goods_mouting_genre, '{{.snd.Genre}}'));
		$('#function_info').html(setOptions(goods_function_info, '{{.snd.FunctionInfo}}'));
	});	
});

function setOptions(data ,def) {
	var opt = '<option value=""></option>';
	$.each(data, function(index, value){
		opt += '<option value="'+ value.val +'" '+ (def==value.val ? 'selected':'') +'>'+ value.val +'</option>';
	});
	return opt;
}
$("#formtable").validator({
    submit: function() {
        if(this.isFormValid()) {
            var that = $("#formtable");
            $.ajax({
                url: location.href
                , type: 'post'
                , data: that.serialize()
                , dataType: 'json'
                , success: function (response) {
                    layer.msg(response.msg);
                    if (response.code === 0) {
                        setTimeout(function () {
                            if(typeof parent.dialogReback == 'function') {
                                parent.dialogReback();
                            }
                            parent.layer.closeAll('iframe');
                        }, 1000);
                    }
                }
                , error: function (error) {
                    layer.msg('数据提交失败！');
                }
            });
        }
        return false;
    }
});

</script>